package br.com.gaacorp.sai.webapp.action;

import java.io.Serializable;

import br.com.gaacorp.sai.model.SchoolClass;
import br.com.gaacorp.sai.service.GenericManager;

public class SchoolClassForm extends BasePage implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2342796791899247043L;
	private GenericManager<SchoolClass, Long> schoolClassManager;
	private SchoolClass schoolClass = new SchoolClass();
	private Long schoolClassId;

	public SchoolClassForm() {
	}

	public String delete() {
		schoolClassManager.remove(schoolClass.getSchoolClassId());
		addMessage("schoolClass.deleted");

		return "schoolClassList";
	}

	public String edit() {
		// Comparison to zero (vs. null) is required with MyFaces 1.2.2, not
		// with previous versions
		if (schoolClassId != null && schoolClassId != 0) {
			schoolClass = schoolClassManager.get(schoolClassId);
		} else {
			schoolClass = new SchoolClass();
		}

		return "schoolClassForm";
	}

	public SchoolClass getSchoolClass() {
		return schoolClass;
	}

	public Long getSchoolClassId() {
		return schoolClassId;
	}

	public GenericManager<SchoolClass, Long> getSchoolClassManager() {
		return schoolClassManager;
	}

	public String save() {
		boolean isNew = (schoolClass.getSchoolClassId() == null || schoolClass
				.getSchoolClassId() == 0);
		schoolClassManager.save(schoolClass);

		String key = (isNew) ? "schoolClass.added" : "schoolClass.updated";
		addMessage(key);

		if (isNew) {
			return "schoolClassList";
		} else {
			return "schoolClassForm";
		}
	}

	public void setSchoolClass(SchoolClass schoolClass) {
		this.schoolClass = schoolClass;
	}

	public void setSchoolClassId(Long schoolClassId) {
		this.schoolClassId = schoolClassId;
	}

	public void setSchoolClassManager(
			GenericManager<SchoolClass, Long> schoolClassManager) {
		this.schoolClassManager = schoolClassManager;
	}
}